package com.iflytek.controller;

import com.iflytek.common.Result;
import com.iflytek.dto.PageDTO;
import com.iflytek.dto.PermissionDTO;
import com.iflytek.service.PermissionService;
import com.iflytek.vo.PageVO;
import com.iflytek.vo.PermissionVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 * @author h_t
 * @since 2023-09-23
 */
@RestController
@RequestMapping("/api/permission")
public class PermissionController{
    @Resource
    public PermissionService permissionService;

    /**
     * 查询所有权限（非分页）findAll
     * @return
     */
    @ApiOperation("查询所有权限（非分页）")
    @GetMapping("")
    Result<List<PermissionVO>> findAll() {
        return permissionService.findAll();
    }

    /**
     * 保存权限项save
     * @param dto
     * @return
     */
    @ApiOperation("保存权限项save")
    @PostMapping("")
    Result<Boolean> savePermission(@RequestBody PermissionDTO dto) {
        return permissionService.savePermission(dto);
    }

    /**
     * 更新权限信息update
     * @param dto
     * @return
     */
    @ApiOperation("更新权限信息")
    @PutMapping("")
    Result<Boolean> updatePermission(@RequestBody PermissionDTO dto) {
        return permissionService.updatePermission(dto);
    }

    /**
     * 权限分页查询findPage
     * @param dto
     * @return
     */
    @ApiOperation("权限分页查询")
    @GetMapping("/page")
    Result<PageVO<PermissionVO>> findPage(PageDTO<PermissionDTO> dto) {
        return permissionService.findPage(dto);
    }

    /**
     * 根据角色获取对应的权限项 getByRoles
     * @param dto
     * @return
     */
    @ApiOperation("根据角色获取对应的权限项")
    @PostMapping("/getByRoles")
    Result<List<PermissionVO>> getByRoles(@RequestBody PermissionDTO dto) {
        return permissionService.getByRoles(dto);
    }

    /**
     * 权限分页查询findById
     * @param id
     * @return
     */
    @ApiOperation("权限分页查询")
    @PostMapping("/{id}")
    Result<PermissionVO> findById(@PathVariable("id") Long id) {
        return permissionService.findById(id);
    }

    /**
     * 根据id删除权限项deleteById
     * @param id
     * @return
     */
    @ApiOperation("根据id删除权限项")
    @DeleteMapping("{id}")
    Result<PermissionVO> deleteById(@PathVariable("id") Long id) {
        return permissionService.deleteById(id);
    }

}